import request from 'umi-request'
import { message } from 'antd'

// request请求拦截器
request.interceptors.request.use((url: string, options: any) => {
  return {
    url: `${url}`,
    options: { ...options, interceptors: true, headers: { Hello: 'hello' } }
  }
})

// request响应拦截器
request.interceptors.response.use(response => {

  if (response.status > 400) {
    const codeMaps = {
      502: "网关错误",
      503: "服务不可用，服务器过载或正在维护",
      504: "网关超时"
    }
    message.error(codeMaps[response.status])
  }

  return response
})

export default request